from cgitb import html
import sys
from urllib import response
import requests

from send_mail import send_mail


def format_msg(my_name=None, my_website=None):
    return 'Name: %s, WebSite: %s' % (my_name, my_website)


def send(name, website=None, to_mail=None, verbose=False):
    assert to_mail != None
    if website:
        msg = format_msg(my_name=name, my_website=website)
    else:
        msg = format_msg(my_name=name)
    if verbose:
        print(name, website, to_mail)

    try:
        send_mail(text=msg, to_mails=[to_mail], html=None)
        sent = True
    except:
        sent = False
    return sent
    # r = requests.get("http://httpbin.org/json")
    # if r.status_code == 200:
    #     return r.json()
    # else:
    #     return "There was an error"


if __name__ == "__main__":
    print(sys.argv)
    name = "Unknown"
    if len(sys.argv) > 1:
        name = sys.argv[1]
    email = None
    if len(sys.argv) > 2:
        email = sys.argv[2]

    response = send(name, to_mail=email, verbose=True)
    print(response)
